package com.service;

import android.app.Application;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;

import com.service.entities.Login;

/**
 * Created by rora0613 on 30.09.13.
 */
public class PizzaApplication extends Application implements SharedPreferences.OnSharedPreferenceChangeListener {

    private Login login;
    private SharedPreferences prefs;

    @Override
    public void onCreate() {
        super.onCreate();
        this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
        this.prefs.registerOnSharedPreferenceChangeListener(this);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    public Login getLogin() {
        String login = prefs.getString("login", "");
        String password = prefs.getString("password", "");
        if (login != null && password != null) {
            this.login = new Login(login, password);
        }
        return this.login;
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
        this.login = null;
    }
}
